package topcoder;

public class GameOfLifeDivTwo {

	public String theSimulation(String init, int T){
		int N = init.length();
		char[] s = init.toCharArray();
		char[] s2 = new char[N];
		
		for(int i = 1; i <= T; i++){
			
			for(int j = 0; j < N; j++){
				
				int count = 0;
				for(int k = j-1; k <= j+1; k++){
					char c;
					if(k == -1)
						c = s[N-1];
					else if(k == N)
						c = s[0];
					else
						c = s[k];
								
					if(c == '1')
						count++;
				}
				
				if(count > 1)
					s2[j] = '1';
				else
					s2[j] = '0';
			}
			
			s = s2;
		}
		
		return new String(s);
	}
	
	public static void main(String[] args) {
		GameOfLifeDivTwo gl = new GameOfLifeDivTwo();
		System.out.println(gl.theSimulation("010101", 5));
	}
}
